#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-07-15 6:43 下午
# @Author  : yangdy
# @File    : 寻找旋转排序数组中的最小值
# @Software: PyCharmCE
from typing import List


class Solution:
    def findMin(self, nums: List[int]) -> int:
        ans = 0
        ln = len(nums)
        i, j = 0, ln-1
        while i < j:
            h = (i + j) // 2
            if nums[h] > nums[j]:
                i = h + 1
            elif nums[h] < nums[j]:
                j = h
        ans = nums[i] if nums[i] < nums[j] else nums[j]
        return ans


solve = Solution()

questions = [
    ([3, 4, 5, 1, 2],),
    ([4, 5, 6, 7, 1, 2],),
    ([4, 5, 6, 7, 0, 1, 2], ),
]

for qi, q in enumerate(questions):
    print(f'#{qi}:', q)
    print('ans:', solve.findMin(q[0]))
